package com.kehutong.applet.admin;

import com.kehutong.applet.entity.AdvertEntity;
import com.kehutong.applet.entity.AppletWhiteEntity;
import com.kehutong.applet.service.AppletWhiteService;
import com.kehutong.common.util.Token;
import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;

/**
 * @program: kht
 * @description: 白名单控制类
 * @author: joneron
 * @create: 2021/5/25
 **/
@MvcAction
@ReqMapping("/admin/crm/applet/white")
public class AppletWhiteController {

    @Inject
    AppletWhiteService advertService;

    @ReqMapping("/page")
    @HasPermission("crm:applet:white:view")
    public Object page(JSONObject jsonObject) {
        return advertService.findPage(jsonObject);
    }

    @ReqMapping("/list")
    @HasPermission("crm:applet:white:view")
    public Object list(JSONObject jsonObject) {
        return advertService.findList(jsonObject);
    }

    @Bean(newInstance=true, copy=true)
    @HasPermission("crm:applet:white:edit")
    @ReqMapping("/save")
    public Object save(AppletWhiteEntity advertEntity, Token token) {
        advertEntity.setCreateName(token.getUsername());
        return advertService.save(advertEntity);
    }

    @Bean(copy=true)
    @HasPermission("crm:applet:white:edit")
    @ReqMapping("/update")
    public Object update(AppletWhiteEntity advertEntity) {

        return advertService.update(advertEntity);
    }

    @HasPermission("crm:applet:white:edit")
    @ReqMapping("/delete")
    public Object delete(AppletWhiteEntity advertEntity) {

        return advertService.deleteById(advertEntity.getId());
    }

    @ReqMapping("/get")
    public Object get(AppletWhiteEntity entity) {

        return Result.success(entity);
    }
}
